
//
//  FANWelcomeViewController.m
//  Weibo - OC
//
//  Created by user on 16/4/20.
//  Copyright © 2016年 user. All rights reserved.
//

#import "FANWelcomeViewController.h"

//#warning 宏定义一定要放到 导入头文件的 上面, 会影响编译

//define this constant if you want to use Masonry without the 'mas_' prefix

#define MAS_SHORTHAND

//define this constant if you want to enable auto-boxing for default syntax

#define MAS_SHORTHAND_GLOBALS


#import <Masonry/Masonry.h>
#import <SDWebImage/UIImageView+WebCache.h>
#import "FANUserAccountModel.h"
#import "FANMainViewController.h"

@interface FANWelcomeViewController ()

@property (nonatomic, strong) UIImageView *iconImageView;

@property (nonatomic, strong) UILabel *label;

@end

@implementation FANWelcomeViewController

-(UIImageView *)iconImageView{
    
    if (!_iconImageView) {
        
        _iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"avatar_default_big"]];
        
        FANUserAccountModel *model = [FANUserAccountModel sharedAccountModel];
        
        if (model != nil) {
            
//            NSLog(@"%@",model.account.avatar_large);
            
//            NSLog(@"%@",model.account.access_token);
            
            [_iconImageView sd_setImageWithURL:[NSURL URLWithString:model.account.avatar_large] placeholderImage:[UIImage imageNamed:@"avatar_default_big"]];
            
        }
    }
    
    return _iconImageView;
}

- (UILabel *)label{
    
    if (!_label) {
        
        _label = [[UILabel alloc] init];
        
        _label.alpha = 0;
        
        _label.text = @"欢迎回来";
        
        _label.textColor = [UIColor darkGrayColor];
        
        _label.font = [UIFont systemFontOfSize:15];
    }
    
    return _label;
}



- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupUI];
}

- (void)viewDidAppear:(BOOL)animated{
    
    [super viewDidAppear:animated];
    
    [self.iconImageView updateConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.view.top).offset(100);
        
    }];
    
    [UIView animateWithDuration:1 delay:1 usingSpringWithDamping:0.4 initialSpringVelocity:0 options:0 animations:^{
        
        [self.view.layer layoutIfNeeded];
        
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:1 animations:^{
            
            self.label.alpha = 1;
            
        } completion:^(BOOL finished) {
            
//            NSLog(@"登录成功");
            
            [[NSNotificationCenter defaultCenter] postNotificationName:@"changeVc" object:nil];
            
//            [UIApplication sharedApplication].keyWindow.rootViewController = [[FANMainViewController alloc] init];
        }];
    }];
}

- (void)setupUI{
    
    self.view.backgroundColor = [UIColor colorWithWhite:247/255.0 alpha:1];
    
    [self.view addSubview:self.iconImageView];
    
    [self.view addSubview:self.label];
    
    self.iconImageView.layer.cornerRadius = 40;
    
    self.iconImageView.layer.masksToBounds = true;
    
    [self.iconImageView makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.equalTo(self.view.centerX);
        
        make.top.equalTo(self.view.top).offset(200);
        
        make.width.height.equalTo(80);
        
    }];
    
    [self.label makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.equalTo(self.view.centerX);
        
        make.top.equalTo(self.iconImageView.bottom).offset(15);
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
